﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
using System.Security.Policy;

namespace Compiler
{
    internal static class DefaultValueGetter
    {
        internal static List<string> GetDefaultReferencedAssemblies()
        {
            List<string> result = new List<string>();
            //AppDomain appDomain = CreateAppDomain();
            //try
            //{
            //    Type loaderType = typeof(AssemblyLoader);
            //    AssemblyLoader loader = (AssemblyLoader)appDomain.CreateInstanceFrom(
            //        loaderType.Assembly.Location,
            //        loaderType.FullName).Unwrap();
            //    result = loader.GetDefaultReferencedAssemblies();
            //}
            //finally
            //{
            //    AppDomain.Unload(appDomain);
            //    GC.Collect();
            //}
            AssemblyLoader loader = new AssemblyLoader();
            result = loader.GetDefaultReferencedAssemblies();
            return result;
        }

        internal static List<string> GetDefaultUsingNamespaces()
        {
            List<string> result = new List<string>();
            //AppDomain appDomain = CreateAppDomain();
            //try
            //{
            //    Type loaderType = typeof(AssemblyLoader);
            //    var loader = (AssemblyLoader)appDomain.CreateInstanceFrom(
            //        loaderType.Assembly.Location,
            //        loaderType.FullName).Unwrap();
            //    result = loader.GetDefaultUsingNamespaces();
            //}
            //finally
            //{
            //    AppDomain.Unload(appDomain);
            //    GC.Collect();
            //}
            AssemblyLoader loader = new AssemblyLoader();
            result = loader.GetDefaultUsingNamespaces();

            return result;
        }

        private static AppDomain CreateAppDomain()
        {
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
            setup.ShadowCopyFiles = "true";
            AppDomain appDomain = AppDomain.CreateDomain("AD #2", evidence, setup);

            return appDomain;

        }
    }
}
